package codetop.microsoft.T974;

/**
 * @Author: 18362
 * @Create: 2022-09-08 2:25:09 星期四
 */
class Solution {
    public int subarraysDivByK(int[] nums, int k) {
        int sum = 0, res = 0;
        int[] map = new int[k];
        map[0] = 1;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
            int key = (sum % k + k) % k;
            res += map[key];
            map[key]++;
        }
        return res;
    }
}